
package gui;

import java.awt.BorderLayout;
import java.util.HashMap;
import java.util.Map;

import gui.properties.Properties;
import gui.workspace.Workspace;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JSplitPane;

import controller.SLogoController;

import model.Model;

/**
 * Highest-level GUI class that organizing subcomponents and panels
 * 
 * @author Troy Ferrell
 * @author Shun Fan
 */

public class SLogoGUI extends JFrame 
{
	private static final String MENUBAR_RESOURCE = "src/resources/menubar/MenuBarProperties.txt";
	private static final String TOOLBAR_RESOURCE = "src/resources/ToolbarProperties.txt";
	private static final String PROPERTY_RESOURCE = "src/resources/properties/PropertyClasses.txt";
	
	private Map<String, JComponent> myComponents = new HashMap<String, JComponent>();
	
	public SLogoGUI(SLogoController controller, Model model)
	{
		// TODO: look at using xml for building system components into GUI...may handle splitpane parenting & childs
		
		addSLogoComponentToMap( new Scene(model));
		addSLogoComponentToMap( new Workspace(model));
		addSLogoComponentToMap( new Prompt(model));
        addSLogoComponentToMap( new Properties(PROPERTY_RESOURCE, model, controller));
        addSLogoComponentToMap( new Toolbar(TOOLBAR_RESOURCE, this, controller));
        
        
        JSplitPane splitSceneWorkspace = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, 
        		getSLogoComponent(Workspace.class.getName()), getSLogoComponent(Scene.class.getName()));
        splitSceneWorkspace.setOneTouchExpandable(true);
        
        JSplitPane splitSWPrompt = new JSplitPane(JSplitPane.VERTICAL_SPLIT, 
        		splitSceneWorkspace, getSLogoComponent(Prompt.class.getName()));
        splitSWPrompt.setOneTouchExpandable(true);
        
        JSplitPane splitSWP = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,  
        		getSLogoComponent(Properties.class.getName()),splitSWPrompt);
        
        this.add( getSLogoComponent(Toolbar.class.getName()), BorderLayout.NORTH  );
        this.add(splitSWP, BorderLayout.CENTER);
		
		this.setJMenuBar( new SLogoMenuBar(MENUBAR_RESOURCE, this, controller) );
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	/**
	 * Add component to map of components for view using class name as key
	 * 
	 * @param JComponent - component to add
	 */
	public void addSLogoComponentToMap(JComponent comp)
	{
		myComponents.put(comp.getClass().getName(), comp);
	}
	
	/**
	 * Get component of system based on its name 
	 * - used with reflection and controllers by associating actions with target components
	 * 
	 * @param componentName
	 * @return the associated component
	 */
	public JComponent getSLogoComponent(String componentName)
	{		
		return myComponents.get(componentName);
	}	
}
